#include <Python.h>

#include <string.h>
/* include ViennaRNA fold functions */
#include  "utils.h"
#include  "fold.h"

static PyObject *
mfefold ( PyObject * self, PyObject * args)
{
  const char *seq;
  int window;
  int sts;

  float fe;
  char *s;

  if (! PyArg_ParseTuple(args, "s", &seq))
    return NULL;

  window = strlen(seq);

  /* allocate memory for fold(), could be skipped */
  initialize_fold(window);
  
  /* allocate memory for structure and fold */
  s = (char* ) space(sizeof(char)*(window+1));
  fe =  fold(seq, s);
  
  free_arrays();     /* free arrays used in fold() */
  return Py_BuildValue("fs",fe,s);
}

static PyMethodDef viennaMethods[] = 
  {
	{"mfefold",mfefold,METH_VARARGS,"Calculate secondary structure free energy and structure."},
	{NULL,NULL}
  };
  
void initpyvfold()
{
  PyObject * m;
  m = Py_InitModule("pyvfold",viennaMethods);
}
